package com.company.test24;

import java.util.Comparator;

/**
 * Created by Administrator on 2016.10.19.
 */
public class Test2401 {
    public static <E extends Comparable<E>> void bubbleSort(E[] list){
        for(int i=1;i<list.length;i++){
            for(int j=1;j<list.length;j++){
                if(list[j].compareTo(list[j-1])<0){
                    E e=list[j];
                    list[j]=list[j-1];
                    list[j-1]=e;
                }
            }
        }
    }

    public static <E> void bubbleSort(E[] list,Comparator<? super E> comparator){
        for(int i=1;i<list.length;i++){
            for(int j=1;j<list.length;j++){
                if(comparator.compare(list[j],list[j-1])<0){
                    E e=list[j];
                    list[j]=list[j-1];
                    list[j-1]=e;
                }
            }
        }
    }

    public static void main(String[] args) {
        Integer[] a={2,3,4,6,1};
        bubbleSort(a, (o1, o2) -> o1-o2);

        for(int i=0;i<a.length;i++){
            System.out.println(a[i]);
        }
    }
}
